<?php

	$TEMP->set_file(array('handle' => DIR_IFRAME_VIEW . 'setFacultySchedule.html'));
	
	$schedTimeID = $_GET['id'];
	$FID 		 = $_GET['fid'];
	
	
	if (!empty($FID)) {
		$faculty = $PI->getPersonalInformation($FID);
		$profName = $faculty['first_name'] . ' ' . $faculty['last_name'];
	}
	
	$scheduleTime = $STUD->getScheduleTimeID($schedTimeID);

	if ( isset($_POST['subButton']) ) {
		$if_error	= 0;
		$stid	 = _POST('stid');
		$psid	 = _POST('psid');
		$sec	 = _POST('txtsection');
		$room	 = _POST('txtroom');
		$llval	 = _POST('lec_lab_value');
		if ( empty($psid) )	 { $if_error++; $_psid 	= REQ_FIELD; }
		if ( empty($sec) )	 { $if_error++; $_sec 	= REQ_FIELD; }
		if ( empty($room) )	 { $if_error++; $_room 	= REQ_FIELD; }
		if ( $llval === '' ) { $if_error++; $_llval = REQ_FIELD; }
		if ( $if_error == 0 ) {
			$strArray = array('sched_time'	=> $stid,
							  'prof_subj' 	=> $psid,
							  'section'	 	=> $sec,
							  'room'		=> $room,
							  'lec_lab'		=> $llval,
							  'year_id'		=> $activeYear);
			$STUD->insertProfSubjSchedTemp($strArray);
			$if_display = 1;
		}
	}
	else {
		$if_display	= 0;
		$if_error	= 0;
		$_psid  	= '';
		$_sec   	= '';
		$_room  	= '';
		$_llval 	= '';
	}
	
	$profSubjList = $STUD->getProfSubjList($FID);
	$selectSubjList = '<select name="psid" id="txtsubj" class="select-auto-input" onchange="subjList();">';
	$selectSubjList .= '<option value="" class="color-grey">--- SUBJECTS ---</option>';
		if ( !empty($profSubjList) ) {
			foreach($profSubjList as $profSubjListValue) {
				$selectSubjList .= '<option value="' . $profSubjListValue['prof_subj_idPK'] . '" ' . $selectedSubj . '>' . $profSubjListValue['course_code'] . ' : ' . $profSubjListValue['subj_code'] . '</option>';
			}
		}
	$selectSubjList .= '</select>';
	
	# ---------------------------------------------
	
	$profSectionList = $STUD->getProfSectionList($schedTimeID);
	$selectSectionList = '<select name="txtsection" id="txtsection" class="select-auto-input" onchange="sectionList();">';
	$selectSectionList .= '<option value="" class="color-grey">--- SECTIONS ---</option>';
		if ( !empty($profSectionList) ) {
			foreach($profSectionList as $profSectionListValue) {
				$selectSectionList .= '<option value="' . $profSectionListValue['section_idPK'] . '" ' . $selectedSection . '>' . $profSectionListValue['section_desc'] . '</option>';
			}
		}
	$selectSectionList .= '</select>';
	
	# ---------------------------------------------
	
	$profRoomList = $STUD->getProfRoomList($schedTimeID);
	$selectRoomList = '<select name="txtroom" id="txtroom" class="select-auto-input" onchange="roomList();">';
	$selectRoomList .= '<option value="" class="color-grey">--- ROOMS ---</option>';
		if ( !empty($profRoomList) ) {
			foreach($profRoomList as $profRoomListValue) {
				$selectRoomList .= '<option value="' . $profRoomListValue['room_idPK'] . '" ' . $selectedRoom . '>' . $profRoomListValue['room_desc'] . '</option>';
			}
		}
	$selectRoomList .= '</select>';
	
	$TEMP->set_var(array('prof_name' 	=> $profName,
						 'stid' 		=> $schedTimeID,
						 'fid' 			=> $FID,
						 'from' 		=> $scheduleTime['sched_from'],
						 'to' 			=> $scheduleTime['sched_to'],
						 'day' 			=> $scheduleTime['sched_day'],
						 'hrs' 			=> $scheduleTime['sched_time'],
						 'subj'			=> $selectSubjList,
						 'section'		=> $selectSectionList,
						 'room'			=> $selectRoomList,
						 
						 'year_id'		=> $activeYear,
						 
						 'w_error'		=> $if_error,
						 'if_display'	=> $if_display,
						));

?>